import { View } from "@tarojs/components";
import React, { Component } from "@tarojs/taro";
import Echarts from '../components/Echarts'

// 地图
export default class RegionalStatistics extends Component{
  

    setChartOptions(chart) {

        websiteStatics(moment().subtract(10,"day"),moment().format('YYYY-MM-DD')).then(res => {
        console.log(res);
            const data = res.data.data
            const {chartData,websiteList} = data
            const lengendData = websiteList.map(item => item.value);
            console.log(lengendData);
            chartData.forEach(item => {
                item.x = item.x.substring(5, 10)
            });
            const xAxisData = chartData.map(item => item.x)
            console.log(xAxisData);
            
            //构造数据
            const seriesData = websiteList.map((item,index) => {

                const data = chartData.map(chartDataItem => {
                   return  chartDataItem[item.key]
                })

                return {
                    name: item.value,
                    type: 'line',
                    stack: '总量',
                    data,
                    lineStyle: {
                        color:getColorByIndex(index)
                    }
                }
            })
            console.log(seriesData);

  
  chart.setOption(option);
   
        })






}


    render() {
        const height = Taro.pxTransform(500);
        return (
            <View >
                <View className='caption '>
                    地域统计
                </View>
                <Echarts setChartOptions={this.setChartOptions.bind(this)} height={height}/>
            </View>
        )
    }
}